FROM jenkins

USER root
RUN apt-get update && apt-get install -y sudo vim openjdk-7-jdk

# RVM install
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 && \
    curl -L https://get.rvm.io | /bin/bash -s stable 

RUN /bin/bash -l -c "source /etc/profile.d/rvm.sh;" && \
    /bin/bash -l -c "rvm requirements;" 

ENV RVM_HOME /usr/local/rvm
ENV RUBY_VERSION 2.3.2

RUN ${RVM_HOME}/bin/rvm install ruby-${RUBY_VERSION}
RUN ${RVM_HOME}/bin/rvm alias create default ruby-${RUBY_VERSION}
RUN ${RVM_HOME}/bin/rvm list

USER jenkins

RUN /bin/bash -l -c "source /etc/profile.d/rvm.sh;"
RUN /bin/bash -l -c "ruby -v;"

# allow to define the number of the executors
COPY conf/executors.groovy /usr/share/jenkins/ref/init.groovy.d/executors.groovy
COPY conf/plugins.txt /usr/share/jenkins/ref/
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt

ENV RUBY_HOME /usr/local/rvm/rubies/ruby-${RUBY_VERSION}/
ENV PATH ${RVM_HOME}/bin/:${RUBY_HOME}/bin:${PATH}

USER root

RUN /bin/bash -l -c "gem install jenkins_api_client;"

# set up the Maven
ENV MAVEN_VERSION 3.3.9

RUN wget http://mirrors.cnnic.cn/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz -P /tmp
WORKDIR /tmp
RUN tar zxvf apache-maven-${MAVEN_VERSION}-bin.tar.gz
RUN cp -r apache-maven-${MAVEN_VERSION} /usr/local/ && rm apache-maven-${MAVEN_VERSION}-bin.tar.gz 
ENV MAVEN_HOME /usr/local/apache-maven-${MAVEN_VERSION}
COPY conf/.m2/settings.xml ${MAVEN_HOME}/conf
ENV PATH ${MAVEN_HOME}/bin:${PATH}

#scala installation
ENV SCALA_VERSION 2.11.8
ENV SCALA_TAR_URL http://www.scala-lang.org/files/archive 

RUN wget ${SCALA_TAR_URL}/scala-${SCALA_VERSION}.tgz -P /tmp
WORKDIR /tmp
RUN tar xvf scala-${SCALA_VERSION}.tgz && \
	mv scala-${SCALA_VERSION} /usr/local && \
	rm scala-${SCALA_VERSION}.tgz
ENV SCALA_HOME /usr/local/scala-${SCALA_VERSION}
ENV PATH ${SCALA_HOME}/bin:${PATH}
ENV JAVA7_HOME /usr/lib/jvm/java-7-openjdk-amd64/

# set up the Maven repository
RUN echo "192.168.4.201	mvn.csdn.net maven.csdn.net" >> /etc/hosts

WORKDIR ${JENKINS_HOME}
USER jenkins

RUN mvn -version
RUn scala -version

# set up the MAVEN settings.xml
ADD conf/.m2 ${JENKINS_HOME}/.m2
RUN ls -altr

